package node

import (
	"os"
	"sync"
)

// roles
const (
	RoleMaster = "master"
	RoleSlave  = "slave"
)

// schedule types
const (
	ScheduleTypeAI    = "ai"
	ScheduleTypeVideo = "video"
)

var mutex = &sync.RWMutex{}
var nodeRole = RoleMaster

// GetNodeRole get node role
func GetNodeRole() string {
	mutex.RLock()
	defer mutex.RUnlock()

	switch os.Getenv("NODE_ROLE") {
	case RoleSlave:
		return RoleSlave
	case RoleMaster:
		return RoleMaster
	}

	return nodeRole
}

// SetNodeRole set node role
func SetNodeRole(role string) {
	mutex.Lock()
	defer mutex.Unlock()

	switch role {
	case RoleMaster, RoleSlave:
		nodeRole = role
	}
}